home *** CD-ROM | disk | FTP | other *** search
- /* PSPADDR3 author/revised by Jim Deming 6-11-87 Terripin Station
- - prints the addresses of all the PSP's currently being used in memory and
- the handles opened in each of those processes.
- Handy if you have a lot of parent and child processes loaded.
- - was compiled using Turbo C ver. 1.00
- - was converted from Lattice version. Turbo C allows you to access the
- segment registers as Keywords, i.e. no definition of _DS. For a list
- of all Keywords see Page 199 Turbo C User's Guide.
- Cprintf does not work the same as Lattice. Had to add <CR>.
- Extern definitions are different.
- TurboC has no rstdta().
-
- - ASSUMES your environment area does not exceed 1000 bytes. If it does you
- need to change the array, environment, and the value in movedata().
- DOS has a theoretical maximum of 32K for its environment.
- - chgd for DOS 3.3, ps.environ is not null in command.com, instead after
- the double null is the name of the command processor i.e. COMMAND.COM
- */
-
- struct PROG_S_PRE { /* Program Segment Prefix */
- unsigned int interrpt; /* first two bytes are the instruction int 20h */
- /* this is a carryover from CP/M when you could */
- /* jump to the first byte of your program to exit */
- unsigned int machine; /* Memory size in paragraphs (16-bytes blocks) */
- char dos1;
- char call_dis[5]; /* FAR CALL to MS-DOS function dispatcher */
- unsigned long Int22; /* previous INT 22h, terminate process address IP,CS */
- unsigned long Int23; /* previous INT 23h, CNTRL-C exit address IP,CS */
- unsigned long Int24; /* previous INT 24h, Critical Error address IP,CS */
- unsigned int pre_psp; /* previous PSP segment */
- unsigned char hndl[20]; /* file handles - FF means the handle not assigned */
- unsigned int environ; /* segment address of the environment block */
- char dos2[4];
- unsigned int num_hdl; /* number of dos handles allocated */
- unsigned int hndl_off; /* offset of where the file handles are located */
- unsigned int hndl_seg; /* segment of where the file handles are located */
- char dos3[24];
- char dispatch[12]; /* code to call MS-DOS dispatcher INT 21 instructions */
- char fcb1[16]; /* unopened File Control Block #1 */
- char fcb2[16]; /* unopened File Control Block #2 */
- char dos4[4];
- char dta[128]; /* default Disk Transfer Area */
- } ps;
-
- struct EXTENDED_UNOPENED_FCB {
- char extd;
- char res[5];
- char attr;
- char drive;
- char file[8];
- char ext[3];
- unsigned int cur_blk;
- unsigned int rec_sz;
- unsigned long file_sz;
- unsigned int date;
- unsigned int time;
- char res2[8];
- unsigned char cur_rec;
- unsigned long rel_rec;
- } exfcb;
-
-
-
- extern int _psp[];
- /* Lattice externs
- extern int _env;
- extern int _esize;
- extern int _ss;
- TurboC externs */
- extern char **__argv;
-
- char environment[1000];
- char command_com[] = "COMMAND.COM";
- char *double_null();
-
- void main()
- {
-
- unsigned int psp;
- char *p;
- int cmd_com=0;
- int first_time = 1;
-
- /* Lattice builds an exact image of the environment area in its data segment.
- Turbo C builds an exact image of the environment strings but leaves off the
- trailing string which contains is the program name. So I dropped the
- following test.
-
- if( *(long *)(_env+_esize-2) != 0x00010000 )
- {
- cprintf("Your operating system does not have the name of your\r\n");
- cprintf("program at the end of the environment. You need DOS 3.1 or\r\n");
- cprintf("above. Or you are running Novell Advance Netware ver 1.02\r\n");
- cprintf("which clobbers the name area.\r\n");
- _exit(1);
- }
- */
-
- /* psp = _psp[1]; / * 'Lattice' get the segment word not the offset word */
- psp = _psp[0]; /* Turbo C carries only the segment since offset is 0 */
-
- /* get current volume name and put in dta */
- exfcb.extd = 0xff; /* makes it an extended fcb */
- exfcb.attr = 0x08; /* asking for volume */
- exfcb.drive = 0; /* of current drive */
- strcpy( exfcb.file, "???????????"); /* both fields, file & ext */
-
- /* rstdta(); / * reset DTA to be pointing in the PSP - a Lattice function */
- setdta( 0x80, psp ); /* TurboC equivalent of rstdta() */
-
- bdos( 0x11, &exfcb, 0 );
-
- do
- {
- /* move chucks of memory into our data segment area so that we can work with it */
- movedata( psp, 0, _DS, &ps, sizeof( struct PROG_S_PRE) );
- movedata( ps.environ, 0, _DS, &environment, 1000 );
-
- /* easy way to get progname for current program */
- if( first_time )
- {
-
- /* Lattice version getting full path of program name after environment strings
- cprintf("I'm %s with machine memory of %dK\r\n",
- ( _env + _esize +2 ), ps.machine >> 6 );
- */
- /* Turbo C missing program name after environment so use argv */
- cprintf("I'm %s with machine memory of %dK\r\n",
- *__argv, ps.machine >> 6 );
- if( ps.dta[0] == '\377' )
- {
- ps.dta[19] = '\0';
- cprintf(" current volume name is %s\r\n", &ps.dta[8]);
- }
- cprintf("\r\n");
- first_time = 0;
- }
-
- if( ps.pre_psp == ps.hndl_seg ) cmd_com = 1; /* in COMMAND.COM */
- if( ps.environ == 0 ) /* not DOS 3.3 */
- p = command_com;
- else {
-
- /* find the name of the program following the environment space, Page 4-3 of
- MS-DOS manual, document # 8411-310-02, part # 036-014-012 */
- p = environment;
- while( *double_null( &p ));
-
- if( cmd_com ) p++; else p += 3;
- }
- cprintf("psp at %dK for %s", psp>>6, p );
- cprintf(" maximum number of handles is %d\r\n",ps.num_hdl);
- if( ps.hndl_off == 0x18 && ps.hndl_seg == psp )
- {
- /* display which handles are active for each program */
- /* the field psp is being used as a work int - not good form but ...*/
- for( psp = 0; psp < 20; psp++)
- {
- if( ps.hndl[psp] != 0xff )
- cprintf(" %d",psp);
- }
- cprintf("\r\n");
- psp = ps.pre_psp;
- } else {
- cprintf("handles not in psp ");
- }
- } while( ! cmd_com );
- }
- char *double_null( p )
- char **p;
- {
- while( *(*p)++ );
- return( *p );
- }